package me.zhengjie.modules.finace_taxation.service;

import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.finace_taxation.domain.FtService;
import me.zhengjie.modules.finace_taxation.service.mapper.FtServiceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class ReidsKeyExpirationListener extends KeyExpirationEventMessageListener {

    @Autowired
    private FtServiceMapper ftServiceMapper;

    public ReidsKeyExpirationListener(RedisMessageListenerContainer redisMessageListenerContainer) {
        super(redisMessageListenerContainer);
    }

    /**
     * 针对 redis 数据失效事件，进行数据处理
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        // 拿到key
        FtService ftService = new FtService();
        ftService.setId(message.toString());
        ftService.setActivityFlag(0);
        ftService.setActivityId(null);
        ftServiceMapper.updateById(ftService);
    }

}
